package net.xdclass.xdclass_shiro.controller;

import net.xdclass.xdclass_shiro.domain.User;
import net.xdclass.xdclass_shiro.dto.JsonData;
import net.xdclass.xdclass_shiro.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author zhangsj
 * @date 2020/5/2 10:27
 */
@RestController
@RequestMapping("pub")
public class PublicController {

    @Autowired
    private UserService userService;

    @GetMapping("/find_user_info")
    public Object findUserInfo(@RequestParam("username") String username) {
        return userService.findAllUserInfoByUsername(username);
    }

    @RequestMapping("/need_login")
    public JsonData needLogin() {
        return JsonData.builder().code("-2").message("温馨提示：请使用对应账号登录").build();
    }

    @RequestMapping("/not_permit")
    public JsonData notPermit() {
        return JsonData.builder().code("-3").message("温馨提示：拒接访问，没有权限").build();
    }

    @RequestMapping("/index")
    public JsonData index() {
        ArrayList<Object> list = new ArrayList<>();
        list.add("MySQL");
        list.add("Java");
        list.add("Python");
        list.add("C++");
        list.add("c#");
        list.add("go");
        return JsonData.buildSuccess(list);
    }

    public JsonData login(@RequestBody User user, HttpServletRequest request, HttpServletResponse response){
        Subject subject = SecurityUtils.getSubject();

        new HashMap<>()
    }
}
